home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / tvision / tpictu / tpicture.h < prev   
Encoding:
C/C++ Source or Header  |  1991-11-17  |  3.7 KB  |  89 lines

  1. // *********************************************************************
  2. // This file contains the definitions for class TPicture derived from
  3. // class TInputLine.  Even though I have some doubts about how elegant
  4. // the definition of this class is, it works.  TPicture's constructor
  5. // is defined by specifying the bounds (just like in TInputLine) and
  6. // the mask string.  From the length of the maskstring maxLen is
  7. // calculated "privately" by the member functions.  The string mask
  8. // uses the characters #?&@! and ~.  The characters are treated as
  9. // follows:
  10. //              #  -  only a digit is accepted
  11. //              ?  -  letter (any case)
  12. //              &  -  letter (convert to uppercase)
  13. //              @  -  any character
  14. //              !  -  any character (convert to uppercase)
  15. //              ~  -  digits 0 to 9, . (period) and - (minus sign)
  16. //
  17. //  Any other character will appear literally, and its position in the
  18. //  entry field will be protected.
  19. //
  20. //  examples for mask:
  21. //
  22. //     "(###) ###-####"  for a phone number (digits only)
  23. //     "##/##/##"        a numeric entry for a date
  24. //     "~~~~~~~~~"       a number (digits,.,-)
  25. //     "##-&&&-##"       another date format (03-JAN-91)
  26. //     etc.
  27. //
  28. //   The streamable part of this class compiles fine.  I have not been
  29. //   able to test it yet.  Any help will be accepted.  My compuserve
  30. //   user number is 73257,2655.
  31. //
  32. //   I wrote some internal functions for the class as private member
  33. //   functions.  I suppose it's more elegant to write static functions
  34. //   within the file in which the class is defined because the user will
  35. //   not have any access whatsoever to those functions.  I did not do
  36. //   it this way, for I have the doubt at the beginning and chose this
  37. //   alternative.  Any comment from an expert in C++ will be well received.
  38. //   Which way is better?
  39. //
  40. //   Any comments on this TPicture class will be appreciated.  The next
  41. //   step would be to add a history class for TPicture.
  42. //
  43. //   TPicture was written by Gonzalo Isaza, compuserve member No. 73257,2655
  44. //   This object can be freely distributed to other users without incurring
  45. //   in any copyright violation.  Should any modification be made to this
  46. //   object please notify such change via compuserve.  This notification
  47. //   is requested so that many people can benefit from the changes to the 
  48. //   object.  
  49. //
  50. //*************************************************************************
  51.  
  52. #define  STRINGMASK  "#?&@!~"
  53.  
  54. char  capitalize(char c);
  55.  
  56. class TPicture : public TInputLine     // define a new input line class
  57. {
  58. protected:
  59.   char   *mask;
  60.  
  61. public:
  62.   static const char  * const name;
  63.  
  64.   TPicture(const TRect& bounds,char *maskstring);
  65.   ~TPicture();
  66.   virtual void handleEvent(TEvent& event);   // override event handling
  67.   virtual Boolean valid(ushort command);
  68.   virtual void *read(ipstream&);
  69.   virtual void write(opstream& os);
  70.   void setData(void *rec);
  71.   static  TStreamable  *build();
  72.  
  73. protected:
  74.  
  75.   TPicture(StreamableInit) : TInputLine(streamableInit){}
  76.  
  77. private:
  78.   virtual int  NextPos(int place,int increment=1);
  79.   virtual void HomePos() {curPos=selStart=selEnd=NextPos(-1);}
  80.   virtual void LastPos() {curPos=selStart=selEnd=NextPos(strlen(mask),-1);}
  81.   virtual Boolean Insert(char c);  // Insert char in Picture
  82.   virtual Boolean RemChar();    //remove char at current cursor Position
  83.   virtual Boolean validChar(char c,char cmask); // check c for picture cmask
  84.   virtual Boolean DelBlock();  // deletes selected characters
  85.   virtual char ConvertChar(char c,char cmask)
  86.     { return (cmask=='&' || cmask=='!')? c=capitalize(c) : c;}
  87.   virtual const char *streamableName() const  {return name;}
  88. };
  89.